package services

import (
	"imooc.com/demo_pms/dao"
	"imooc.com/demo_pms/datasources"
	"imooc.com/demo_pms/models"
)

type UserService interface {
	Create(data *models.UserInfo) error
	Update(data *models.UserInfo, cols []string) error
	Search(sql string) []models.UserInfo
	BatchCreate(dataList []models.UserInfo) (int, error)
	Query(sql string) ([]map[string][]byte, error)
}

type userInfoService struct {
	dao *dao.UserDao
}

func NewUserInfoService() UserService {
	return &userInfoService{
		dao: dao.NewUserDao(datasources.NewDbMaster())}
}

func (s *userInfoService) Create(data *models.UserInfo) error {
	return s.dao.Create(data)
}

func (s *userInfoService) BatchCreate(
	dataList []models.UserInfo) (int, error) {

	return s.dao.BatchCreate(dataList)
}

func (s *userInfoService) Update(data *models.UserInfo, cols []string) error {
	return s.dao.Update(data, cols)
}

func (s *userInfoService) Search(sql string) []models.UserInfo {
	return s.dao.Search(sql)
}

func (s *userInfoService) Query(sql string) ([]map[string][]byte, error) {
	return s.dao.Query(sql)
}
